package com.streamer.app.utils.api

import android.util.Log
import android.widget.Toast
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.streamer.app.bean.AnchorBean
import com.streamer.app.bean.CouponBean
import com.streamer.app.bean.CouponListBean
import com.streamer.app.bean.CoursewareInfoBean
import com.streamer.app.bean.DrawBean
import com.streamer.app.bean.LiveBean
import com.streamer.app.bean.LiveUserBean
import com.streamer.app.bean.LoginBean
import com.streamer.app.bean.LotteryBean
import com.streamer.app.bean.LotteryListBean
import com.streamer.app.bean.MessageBean
import com.streamer.app.bean.ProductDateBean
import com.streamer.app.bean.ReplayBean
import com.streamer.app.bean.UserInfoBean
import com.streamer.app.bean.liveProductBean
import com.streamer.app.utils.ToastUtil
import com.streamer.app.utils.http.BaseResult
import com.streamer.app.utils.http.PageDataResult
import com.streamer.app.utils.http.retrofit
import com.youpai.yingteda_android.util.Net
import retrofit2.Call
import java.io.File
import okhttp3.MultipartBody
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody.Companion.asRequestBody
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale

class ViewModel : ViewModel() {
    val LoginLV = MutableLiveData<LoginBean?>()
    val UserInfoLV = MutableLiveData<UserInfoBean?>()
    val LiveInfoLV = MutableLiveData<LiveBean?>()
    val LiveInfoDataLV = MutableLiveData<LiveBean?>()
    val LiveNoteTips = MutableLiveData<Any?>()
    val liveStateLv = MutableLiveData<Any?>()
    val stopStateLv = MutableLiveData<Any?>()
    val EndLiveLV = MutableLiveData<String?>()
    val PushLiveNoticeLV = MutableLiveData<String?>()
    val LiveUserCountLV = MutableLiveData<LoginBean?>()
    val MessageListLV = MutableLiveData<BaseResult<MutableList<MessageBean>>?>()
    val LiveUserListLV = MutableLiveData<MutableList<LiveUserBean>?>()

    val CoursewareListLV = MutableLiveData<MutableList<CoursewareInfoBean>?>()
    val CoursewareInfoLV = MutableLiveData<MutableList<CoursewareInfoBean>?>()
    val LiveDisableUserListLV = MutableLiveData<MutableList<LiveUserBean>?>()
    val LiveDefriendUserListLV = MutableLiveData<MutableList<LiveUserBean>?>()
    val DrawListLV = MutableLiveData<MutableList<DrawBean>?>()
    val ListQueryLV = MutableLiveData<MutableList<DrawBean>?>()
    val DrawPushLV = MutableLiveData<BaseResult<DrawBean>?>()
    val CouponLV = MutableLiveData<PageDataResult<CouponBean>?>()
    val CouponPushLv = MutableLiveData<String?>()
    val PublishCouponLV = MutableLiveData<Any?>()
    val AnchorLV = MutableLiveData<PageDataResult<AnchorBean>?>()
    val LikeLiveLV = MutableLiveData<Any?>()
    val CouponListLV = MutableLiveData<PageDataResult<CouponBean>?>()
    val LotterListLV = MutableLiveData<PageDataResult<LotteryListBean>?>()
    val liveProductBeanLV = MutableLiveData<PageDataResult<liveProductBean>?>()
    val onLiveProductBeanLV = MutableLiveData<PageDataResult<liveProductBean>?>()
    val ProductBeanLV = MutableLiveData<BaseResult<ProductDateBean>?>()

    // 专门用于获取商品数量的LiveData
    val OnSaleProductCountLV = MutableLiveData<Int>()
    val OffShelfProductCountLV = MutableLiveData<Int>()
    val ReplayLV = MutableLiveData<ReplayBean?>()
    val ContentLV = MutableLiveData<ReplayBean?>()


    fun login(code: String, nickName: String, isSeConfirm: Boolean) {
        retrofit<BaseResult<LoginBean>> {
            api = Net.create(UserApi::class.java).login(
                mapOf(
                    "clientId" to "a2e43345f6a0f2f64f2fb15fdfca21cf",
                    "grantType" to "anchor",
                    "tenantId" to "000000",
                    "code" to code,
                    "nickName" to nickName,
                    "isSeConfirm" to isSeConfirm,
                )
            )
            onSuccess {
                LoginLV.value = it.data
            }
            onFail { msg, code ->
                ToastUtil.toastShortMessage(msg)
                Log.d("xxxx", "========+$code")
                LoginLV.value = null
            }
            onComplete {}
        }
    }

    fun info() {
        retrofit<BaseResult<UserInfoBean>> {
            api = Net.create(UserApi::class.java).info(

            )
            onSuccess {
                UserInfoLV.value = it.data
            }
            onFail { msg, code ->
                ToastUtil.toastShortMessage(msg)
                UserInfoLV.value = null
            }
            onComplete {}
        }
    }

    fun getLiveInfo() {
        retrofit<BaseResult<LiveBean>> {
            api = Net.create(UserApi::class.java).getLiveInfo(

            )
            onSuccess {
                LiveInfoLV.value = it.data
            }
            onFail { msg, code ->
                ToastUtil.toastShortMessage(msg)
                LiveInfoLV.value = null
            }
            onComplete {}
        }
    }
    fun getLiveData() {
        retrofit<BaseResult<LiveBean>> {
            api = Net.create(UserApi::class.java).getLiveInfo(

            )
            onSuccess {
                LiveInfoDataLV.value = it.data
            }
            onFail { msg, code ->
                ToastUtil.toastShortMessage(msg)
                LiveInfoDataLV.value = null
            }
            onComplete {}
        }
    }

    fun getMyCourseware() {
        retrofit<BaseResult<String>> {
            api = Net.create(UserApi::class.java).getMyCourseware(
                mapOf()
            )
            onSuccess {}
            onFail { msg, code ->
                ToastUtil.toastShortMessage(msg)
            }
            onComplete {}
        }
    }

    fun startLive() {
        retrofit<BaseResult<Any>> {
            api = Net.create(UserApi::class.java).startLive(

            )
            onSuccess {
                liveStateLv.value = it.data
            }
            onFail { msg, code ->
                ToastUtil.toastShortMessage(msg)
                liveStateLv.value = null
            }
            onComplete {}
        }
    }

    fun endLive() {
        retrofit<BaseResult<String>> {
            api = Net.create(UserApi::class.java).endLive(
            )
            onSuccess {
                EndLiveLV.value = it.data
            }
            onFail { msg, code ->
                ToastUtil.toastShortMessage(msg)
                EndLiveLV.value = null
            }
            onComplete {}
        }
    }

    fun pushLiveNotice(tenantId: String, content: String, liveId: String) {
        retrofit<BaseResult<String>> {
            api = Net.create(UserApi::class.java).pushLiveNotice(
                mapOf(
                    "tenantId" to tenantId, "content" to content, "liveId" to liveId
                )
            )
            onSuccess {
                PushLiveNoticeLV.value = it.data
            }
            onFail { msg, code ->
                ToastUtil.toastShortMessage(msg)
                PushLiveNoticeLV.value = null
            }
            onComplete {}
        }
    }

    fun getLastLiveNotice() {
        retrofit<BaseResult<Any?>> {
            api = Net.create(UserApi::class.java).getLastLiveNotice(

            )
            onSuccess {
                Log.d("xxxx", "getLastLiveNotice======>$it")
                LiveNoteTips.value = it.msg
            }
            onFail { msg, code ->
                ToastUtil.toastShortMessage(msg)
                LiveNoteTips.value = null
            }
            onComplete {}
        }
    }

    fun uploadCourseware(file: File) {
        val mediaType = "application/octet-stream".toMediaTypeOrNull()
        val requestFile = file.asRequestBody(mediaType)
        val body = okhttp3.MultipartBody.Part.createFormData("file", file.name, requestFile)
        retrofit<BaseResult<Any?>> {
            api = Net.create(UserApi::class.java).uploadCourseware(body)
            onSuccess {
                Log.d("upload", "uploadCourseware success: $it")
            }
            onFail { msg, code ->
                ToastUtil.toastShortMessage(msg)
            }
            onComplete {}
        }
    }

    fun getCoursewareInfo() {
        retrofit<BaseResult<MutableList<CoursewareInfoBean>?>> {
            api = Net.create(UserApi::class.java).getCoursewareInfo()
            onSuccess {
                CoursewareListLV.value = it.data
            }
            onFail { msg, code ->
                CoursewareListLV.value = null

                ToastUtil.toastShortMessage(msg)
            }
            onComplete {}
        }
    }

    fun getCoursewareInfo(liveId: String) {
        retrofit<BaseResult<MutableList<CoursewareInfoBean>?>> {
            api = Net.create(UserApi::class.java).getCoursewareInfo(liveId)
            onSuccess {
                CoursewareInfoLV.value = it.data
            }
            onFail { msg, code ->
                CoursewareInfoLV.value = null

                ToastUtil.toastShortMessage(msg)
            }
            onComplete {}
        }
    }

    fun uploadCourseware(context: android.content.Context, uri: android.net.Uri) {
        try {
            val cr = context.contentResolver
            val fileName = getFileNameFromUri(cr, uri) ?: "courseware_${System.currentTimeMillis()}"
            val input = cr.openInputStream(uri) ?: return
            val tempFile = File(context.cacheDir, fileName)
            tempFile.outputStream().use { out -> input.copyTo(out) }
            uploadCourseware(tempFile)
        } catch (e: Exception) {
            e.printStackTrace()
            ToastUtil.toastShortMessage("文件处理失败")
        }
    }

    private fun getFileNameFromUri(
        cr: android.content.ContentResolver, uri: android.net.Uri
    ): String? {
        val cursor = cr.query(uri, null, null, null, null)
        cursor?.use {
            if (it.moveToFirst()) {
                val index = it.getColumnIndex(android.provider.OpenableColumns.DISPLAY_NAME)
                if (index != -1) return it.getString(index)
            }
        }
        return null
    }

    fun liveUserCount(liveRoomNo: String) {
        retrofit<BaseResult<LoginBean>> {
            api = Net.create(UserApi::class.java).liveUserCount(
                mapOf(
                    "id" to liveRoomNo
                )
            )
            onSuccess {
                if (it.data != null) {
                    LiveUserCountLV.value = it.data
                } else {
                    LiveUserCountLV.value = null

                }
            }
            onFail { msg, code ->
                ToastUtil.toastShortMessage(msg)
                LiveUserCountLV.value = null
            }
            onComplete {}
        }
    }

    fun stop(liveRoomNo: String) {
        retrofit<BaseResult<Any>> {
            api = Net.create(UserApi::class.java).stop(
                mapOf(
                    "id" to liveRoomNo
                )
            )
            onSuccess {
                    stopStateLv.value = it.data

            }
            onFail { msg, code ->
                ToastUtil.toastShortMessage(msg)
                stopStateLv.value = null
            }
            onComplete {}
        }
    }

    fun pageQuery(
        roomId: String,
        pageSize: Int,
        pageNum: Int,
        orderByColumn: String = "cillum",
        isAsc: String = "mollit",
        disable: Boolean = false,
        defriend: Boolean = false
    ) {
        retrofit<PageDataResult<LiveUserBean>> {
            api = Net.create(UserApi::class.java).pageQuery(
                mapOf(
                    "pageSize" to pageSize,
                    "pageNum" to pageNum,
                    "orderByColumn" to orderByColumn,
                    "isAsc" to "mollit",
                    "roomId" to roomId,
                    "disable" to disable,
                    "defriend" to defriend,
                    "blacklist" to false,
                )

            )
            onSuccess {
                if (disable) {
                    LiveDisableUserListLV.value = it.rows
                } else if (defriend) {
                    LiveDefriendUserListLV.value = it.rows
                } else {
                    LiveUserListLV.value = it.rows

                }
            }
            onFail { msg, code ->
                ToastUtil.toastShortMessage(msg)
                LiveUserListLV.value = null
                LiveDisableUserListLV.value = null
            }
            onComplete {}
        }
    }

    fun getById(liveRoomNo: String) {
        retrofit<BaseResult<LoginBean>> {
            api = Net.create(UserApi::class.java).getById(
                liveRoomNo
            )
            onSuccess {
                LiveUserCountLV.value = it.data
            }
            onFail { msg, code ->
                ToastUtil.toastShortMessage(msg)
                LiveUserCountLV.value = null
            }
            onComplete {}
        }
    }

    fun send(message: String, roomId: String) {
        retrofit<BaseResult<LoginBean>> {
            api = Net.create(UserApi::class.java).send(
                mapOf(
                    "message" to message, "roomId" to roomId
                )
            )
            onSuccess {
                LiveUserCountLV.value = it.data
            }
            onFail { msg, code ->
                ToastUtil.toastShortMessage(msg)
                LiveUserCountLV.value = null
            }
            onComplete {}
        }
    }

    fun messageHistory(roomId: String) {
        retrofit<BaseResult<MutableList<MessageBean>>> {


            val dateFormat = SimpleDateFormat("yyyyMMdd", Locale.getDefault())
            val joinDate = dateFormat.format(Date()) // 当前时间
// 结果: "20250623"
            api = Net.create(UserApi::class.java).messageHistory(
                mapOf(
                    "roomId" to roomId,
                    "joinDate" to joinDate,
                )
            )
            onSuccess {
                MessageListLV.value = it
            }
            onFail { msg, code ->
                ToastUtil.toastShortMessage(msg)
                MessageListLV.value = null
            }
            onComplete {}
        }
    }

    fun messagePage(roomId: String, pageSize: Int, pageNum: Int) {
        retrofit<BaseResult<MutableList<MessageBean>>> {
            api = Net.create(UserApi::class.java).messagePage(
                mapOf(
                    "pageSize" to pageSize,
                    "pageNum" to pageNum,
                    "roomId" to roomId,
                )
            )
            onSuccess {
                MessageListLV.value = it
            }
            onFail { msg, code ->
                ToastUtil.toastShortMessage(msg)
                MessageListLV.value = null
            }
            onComplete {}
        }
    }

    fun drawPageQuery(roomId: String, pageSize: Int, pageNum: Int) {
        retrofit<PageDataResult<DrawBean>> {
            api = Net.create(UserApi::class.java).drawPageQuery(
                mapOf(
                    "pageSize" to pageSize,
                    "pageNum" to pageNum,
                    "roomId" to roomId,
                )
            )
            onSuccess {
                DrawListLV.value = it.rows
            }
            onFail { msg, code ->
                ToastUtil.toastShortMessage(msg)
                DrawListLV.value = null
            }
            onComplete {}
        }
    }

    fun listQuery(drawId: String) {
        retrofit<PageDataResult<DrawBean>> {
            api = Net.create(UserApi::class.java).listQuery(
                mapOf(
                    "drawId" to drawId,
                )
            )
            onSuccess {
                ListQueryLV.value = it.rows
            }
            onFail { msg, code ->
                ToastUtil.toastShortMessage(msg)
                ListQueryLV.value = null
            }
            onComplete {}
        }
    }

    fun batchPush(roomId: String, drawId: String, duration: Int) {
        retrofit<BaseResult<DrawBean>> {
            api = Net.create(UserApi::class.java).batchPush(
                mapOf(
                    "drawId" to drawId,
                    "duration" to duration,
                    "roomId" to roomId,
                )
            )
            onSuccess {
                DrawPushLV.value = it
            }
            onFail { msg, code ->
                ToastUtil.toastShortMessage(msg)
                DrawPushLV.value = null
            }
            onComplete {}
        }
    }

    fun winnerList(drawBatchId: String) {
        retrofit<BaseResult<DrawBean>> {
            api = Net.create(UserApi::class.java).winnerList(
                mapOf(
                    "drawBatchId" to drawBatchId,
                )
            )
            onSuccess {
                DrawPushLV.value = it
            }
            onFail { msg, code ->
                ToastUtil.toastShortMessage(msg)
                DrawPushLV.value = null
            }
            onComplete {}
        }
    }

    fun couponList(liveId: String) {
        retrofit<PageDataResult<CouponBean>> {
            api = Net.create(UserApi::class.java).couponList(liveId)
            onSuccess {
                CouponLV.value = it
            }
            onFail { msg, code ->
                ToastUtil.toastShortMessage(msg)
                CouponLV.value = null
            }
            onComplete {}
        }
    }

    fun publishCoupon(
        roomId: String, couponId: String, publishDuration: Int, //倒计时（秒）
        grantNum: Int, //发放数量
        grantTime: Int //发放时长（秒）
    ) {
        retrofit<BaseResult<Any>> {
            api = Net.create(UserApi::class.java).couponGrant(
                mapOf(
                    "liveId" to roomId,
                    "id" to couponId,
                    "countDown" to publishDuration,
                    "grantNum" to grantNum,
                    "grantTime" to grantTime
                )
            )
            onSuccess {
                PublishCouponLV.value = it.data
            }
            onFail { msg, code ->
                ToastUtil.toastShortMessage(msg)
                PublishCouponLV.value = null
            }
            onComplete {}
        }
    }

    fun couponPushList(
        liveId: String, pageSize: Int, //发放数量
        pageNum: Int //发放时长（秒）
    ) {
        retrofit<PageDataResult<CouponBean>> {
            api = Net.create(UserApi::class.java).couponPushList(
                liveId, pageSize, pageNum
            )
            onSuccess {
                CouponListLV.value = it

            }
            onFail { msg, code ->
                ToastUtil.toastShortMessage(msg)
                CouponListLV.value = null
            }
            onComplete {}
        }
    }

    fun getRoomDrawUserList(
        roomId: String,
    ) {
        retrofit<PageDataResult<LotteryListBean>> {
            api = Net.create(UserApi::class.java).getRoomDrawUserList(
                mapOf(
                    "roomId" to roomId
                )
            )
            onSuccess {
                LotterListLV.value = it

            }
            onFail { msg, code ->
                ToastUtil.toastShortMessage(msg)
                LotterListLV.value = null
            }
            onComplete {}

        }
    }


    fun userDisable(
        id: String,
    ) {
        retrofit<BaseResult<Any>> {
            api = Net.create(UserApi::class.java).userDisable(
                mapOf(
                    "id" to id
                )
            )
            onSuccess {
                PublishCouponLV.value = it.msg

            }
            onFail { msg, code ->
                ToastUtil.toastShortMessage(msg)
                PublishCouponLV.value = null
            }
            onComplete {}

        }
    }

    fun userDefriend(
        id: String,
    ) {
        retrofit<BaseResult<Any>> {
            api = Net.create(UserApi::class.java).userDefriend(
                mapOf(
                    "id" to id
                )
            )
            onSuccess {
                PublishCouponLV.value = it.msg

            }
            onFail { msg, code ->
                ToastUtil.toastShortMessage(msg)
                PublishCouponLV.value = null
            }
            onComplete {}

        }
    }

    fun blacklist(
        id: String,
    ) {
        retrofit<BaseResult<Any>> {
            api = Net.create(UserApi::class.java).blacklist(
                mapOf(
                    "id" to id
                )
            )
            onSuccess {
                PublishCouponLV.value = it.msg

            }
            onFail { msg, code ->
                ToastUtil.toastShortMessage(msg)
                PublishCouponLV.value = null
            }
            onComplete {}

        }
    }

    fun liveProductPutaway(
        id: String, showType: String? = null, interval: String? = null, intervalTime: String? = null
    ) {
        val params: Map<String, Any> = if (showType != null) {
            mapOf(
                "id" to id,
                "showType" to showType,
                "interval" to (interval ?: ""),
                "intervalTime" to (intervalTime ?: "")
            )
        } else {
            mapOf("id" to id)
        }

        retrofit<BaseResult<Any>> {
            api = Net.create(UserApi::class.java).liveProductPutaway(params)
            onSuccess {
                PublishCouponLV.value = it.msg
            }
            onFail { msg, code ->
                ToastUtil.toastShortMessage(msg)
                PublishCouponLV.value = null
            }
            onComplete {}
        }
    }

    fun liveProductsPageQuery(
        pageSize: Int, pageNum: Int, roomId: String, status: String, title: String = ""
    ) {
        retrofit<PageDataResult<liveProductBean>> {
            api = Net.create(UserApi::class.java).liveProductsPageQuery(
                mapOf(
                    "pageSize" to pageSize,
                    "pageNum" to pageNum,
                    "roomId" to roomId,
                    "status" to status,
                    "title" to title
                )
            )
            onSuccess {
                liveProductBeanLV.value = it

            }
            onFail { msg, code ->
                ToastUtil.toastShortMessage(msg)
                liveProductBeanLV.value = null

            }
            onComplete {}

        }
    }

    fun onLiveProductsPageQuery(
        pageSize: Int, pageNum: Int, roomId: String, status: String, title: String = ""
    ) {
        retrofit<PageDataResult<liveProductBean>> {
            api = Net.create(UserApi::class.java).liveProductsPageQuery(
                mapOf(
                    "pageSize" to pageSize,
                    "pageNum" to pageNum,
                    "roomId" to roomId,
                    "status" to status,
                    "title" to title
                )
            )
            onSuccess {
                    onLiveProductBeanLV.value = it


            }
            onFail { msg, code ->
                ToastUtil.toastShortMessage(msg)
                    onLiveProductBeanLV.value = null

            }
            onComplete {}

        }
    }

    // 获取售卖中商品数量
    fun getOnSaleProductCount(roomId: String) {
        retrofit<PageDataResult<liveProductBean>> {
            api = Net.create(UserApi::class.java).liveProductsPageQuery(
                mapOf(
                    "pageSize" to 1,
                    "pageNum" to 1,
                    "roomId" to roomId,
                    "status" to "1",
                    "title" to ""
                )
            )
            onSuccess {
                OnSaleProductCountLV.value = it.total
            }
            onFail { msg, code ->
                ToastUtil.toastShortMessage(msg)
                OnSaleProductCountLV.value = 0
            }
            onComplete {}
        }
    }

    // 获取已下架商品数量
    fun getOffShelfProductCount(roomId: String) {
        retrofit<PageDataResult<liveProductBean>> {
            api = Net.create(UserApi::class.java).liveProductsPageQuery(
                mapOf(
                    "pageSize" to 1,
                    "pageNum" to 1,
                    "roomId" to roomId,
                    "status" to "0",
                    "title" to ""
                )
            )
            onSuccess {
                OffShelfProductCountLV.value = it.total
            }
            onFail { msg, code ->
                ToastUtil.toastShortMessage(msg)
                OffShelfProductCountLV.value = 0
            }
            onComplete {}
        }
    }

    fun taught(
        id: String
    ) {
        retrofit<BaseResult<Any>> {
            api = Net.create(UserApi::class.java).taught(
                mapOf(
                    "id" to id
                )
            )
            onSuccess {
                PublishCouponLV.value = it

            }
            onFail { msg, code ->
                PublishCouponLV.value = null
                ToastUtil.toastShortMessage(msg)
            }
            onComplete {}

        }
    }

    fun cancelTaught(
        id: String
    ) {
        retrofit<BaseResult<Any>> {
            api = Net.create(UserApi::class.java).cancelTaught(
                mapOf(
                    "id" to id
                )
            )
            onSuccess {
                PublishCouponLV.value = it

            }
            onFail { msg, code ->
                PublishCouponLV.value = null
                ToastUtil.toastShortMessage(msg)
            }
            onComplete {}

        }
    }

    fun like(
        count: String
    ) {
        retrofit<BaseResult<Any>> {
            api = Net.create(UserApi::class.java).like(
                mapOf(
                    "count" to count
                )
            )
            onSuccess {
                LikeLiveLV.value = it

            }
            onFail { msg, code ->
                LikeLiveLV.value = null
                ToastUtil.toastShortMessage(msg)
            }
            onComplete {}

        }
    }

    fun getFullInfo(
        productId: String
    ) {
        retrofit<BaseResult<ProductDateBean>> {
            api = Net.create(UserApi::class.java).getFullInfo(
                productId
            )
            onSuccess {
                ProductBeanLV.value = it

            }
            onFail { msg, code ->
                ProductBeanLV.value = null
                ToastUtil.toastShortMessage(msg)
            }
            onComplete {}

        }
    }

    fun closeOpenYellowCar(
    ) {
        retrofit<BaseResult<Any>> {
            api = Net.create(UserApi::class.java).closeOpenYellowCar(

            )
            onSuccess {
                PublishCouponLV.value = it

            }
            onFail { msg, code ->
                PublishCouponLV.value = null
                ToastUtil.toastShortMessage(msg)
            }
            onComplete {}

        }
    }

    fun closeOpenGiftEffect(
    ) {
        retrofit<BaseResult<Any>> {
            api = Net.create(UserApi::class.java).closeOpenGiftEffect(

            )
            onSuccess {
                PublishCouponLV.value = it

            }
            onFail { msg, code ->
                PublishCouponLV.value = null
                ToastUtil.toastShortMessage(msg)
            }
            onComplete {}

        }
    }

    fun closeOpenTipping(
    ) {
        retrofit<BaseResult<Any>> {
            api = Net.create(UserApi::class.java).closeOpenTipping(

            )
            onSuccess {
                PublishCouponLV.value = it

            }
            onFail { msg, code ->
                PublishCouponLV.value = null
                ToastUtil.toastShortMessage(msg)
            }
            onComplete {}

        }
    }

    fun anchorPage(
        pageSize: Int, pageNum: Int, liveId: String
    ) {
        retrofit<PageDataResult<AnchorBean>> {
            api = Net.create(UserApi::class.java).anchorPage(
                pageNum, pageSize, liveId
            )
            onSuccess {
                AnchorLV.value = it

            }
            onFail { msg, code ->
                AnchorLV.value = null
                ToastUtil.toastShortMessage(msg)
            }
            onComplete {}

        }
    }

    fun delCourseware(
        id: String
    ) {
        retrofit<BaseResult<Any>> {
            api = Net.create(UserApi::class.java).delCourseware(
                mapOf("id" to id)
            )
            onSuccess {
                PublishCouponLV.value = it

            }
            onFail { msg, code ->
                PublishCouponLV.value = null
                ToastUtil.toastShortMessage(msg)
            }
            onComplete {}

        }
    }
    fun replay(
        id: String
    ) {
        retrofit<BaseResult<ReplayBean>> {
            api = Net.create(UserApi::class.java).replay(
                id
            )
            onSuccess {
                ReplayLV.value = it.data

            }
            onFail { msg, code ->
                ReplayLV.value = null
                ToastUtil.toastShortMessage(msg)
            }
            onComplete {}

        }
    }
    fun content(
        contentId: String
    ) {
        retrofit<BaseResult<ReplayBean>> {
            api = Net.create(UserApi::class.java).content(
                contentId
            )
            onSuccess {
                ContentLV.value = it.data

            }
            onFail { msg, code ->
                ContentLV.value = null
                ToastUtil.toastShortMessage(msg)
            }
            onComplete {}

        }
    }
}




